import socket


# 创建TCP套接字
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# 获取本地主机名
host = socket.gethostname()
port = 12345

# 绑定到指定地址和端口
server_socket.bind((host, port))

# 开始监听，最大连接数为5
server_socket.listen(5)
print(f"Server is listening on {host}:{port}")
while True:
    # 接受客户端连接
    client_socket, addr = server_socket.accept()
    print(f"Got a connection from {addr}")
    message = "Hello, client!".encode('utf-8')
    # 向客户端发送消息
    client_socket.send(message)
    client_socket.close()